
package jweslley.ContestVolumes.VolumeCVI;

import java.util.Scanner;

import jweslley.Problem;
import jweslley.Problem.Status;

/**
 * http://icpcres.ecs.baylor.edu/onlinejudge/external/106/10656.html
 *
 * @author  Jonhnny Weslley
 * @version 1.00, 21/10/2008
 */
@Problem(Status.Accepted)
public class MaximumSumII {

	public static void main(String[] args) {
		StringBuilder out = new StringBuilder();
		Scanner in = new Scanner(System.in);
		int n, x;
		boolean newsum;
		while ((n = in.nextInt()) != 0) {
			newsum = false;
			while (n --> 0) {
				x = in.nextInt();
				if (x == 0) continue;
				if (newsum) out.append(' ');
				out.append(x);
				newsum = true;
			}
			if (newsum)
				out.append('\n');
			else
				out.append("0\n");
		}
		System.out.print(out);
	}

}
